//关键字高亮
function setHeightKeyWord(id, keyword, color, bold) { 
			if (keyword == "") 
				return;

			var tempHTML = $("." + id).html();
			var htmlReg = new RegExp("\<.*?\>", "i");
			var arrA = new Array(); 
			for (var i = 0; true; i++) { 
				var m = htmlReg.exec(tempHTML); 
				if (m) { 
					arrA[i] = m; 
				} 
				else { 
					break; 
				} 
				tempHTML = tempHTML.replace(m, "[[[[" + i + "]]]]"); 
			} 
			var replaceText='';
			if (bold) {
                replaceText = '<b style="color:' + color + ';">'+keyword+'</b>';
            }else {
                replaceText = '<font style="color:' + color + ';">'+keyword+'</font>';
            }

			var arrayWord = keyword.split(','); 
			for (var w = 0; w < arrayWord.length; w++) { 
				var r = new RegExp("(" + arrayWord[w].replace(/[(){}.+*?^$|\\\[\]]/g, "\\$&") + ")", "ig");
				tempHTML = tempHTML.replace(r,replaceText);
			}
			for (var i = 0; i < arrA.length; i++) { 
				tempHTML = tempHTML.replace("[[[[" + i + "]]]]", arrA[i]); 
			} 
			$("." + id).html(tempHTML); 
} 
$(function() { 
	$("#search_btn").click(function() { 
		var search_val = $(".search_input").val();
        if(search_val==''){
            alert('请输入您要搜索的内容！');
            return;
        }

        $.ajax({
            url: API_URL+'curriculum/searchCurriculum?title='+search_val+'&openid='+openid,
            type: 'GET',
            dataType: "JSON",
            data:'',
            success: function (obj){
                if (obj.status.code == 0) {
                    var str='';
                    var myData = obj.basedata.data;
                    if(myData.length == 0){
                        str = '<img class="no_relation" src="../img/no_relation.png" alt=""/>';
                        $('#show_item').html(str);
                        return;
                    }

                    //跳转详情
                    //status_detial.html?agentopenid=oidl4s4aayKHtuP5eBKl4bVK__Kk&openid=11&detialId=8a2d8d544c07cbbf014c2c168b8a02cd&user_status=1
                    for(var i=0;i<myData.length;i++){
                        if(myData[i].agent_icon==null || myData[i].agent_icon==''){
                            myData[i].agent_icon = '../img/default.png';
                        }
                        var welldone ='';
                        if(myData[i].pa_state == 1){
                            welldone = ' welldone';
                        }
                        str +='<div class="items_content">'+
                                
                                    '<dl>'+
                                        '<dd><img src="'+myData[i].agent_icon+'" alt=""></dd>'+
                                        '<dt>'+
                                            '<h3>'+myData[i].agent_name+'</h3>'+
                                            '<p class="time">'+myData[i].createtime_str+'</p>'+
                                        '</dt>'+
                                    '</dl>';
                            str += '<a href="status_detial.html">'+
                        if(myData[i].type == 'photo') {
                            str += '<p class="published_text clear">' + myData[i].content + '</p>';
                            if (myData[i].photo != null && myData[i].photo != '') {
                                //alert('有图:'+myData[i].photo);
                                str += '<img class="detials_img" src=\"' + myData[i].photo + '\" alt=""/>';
                            }
                        }else if(myData[i].type == 'vido'){
                            str += '<p class="published_text clear">'+myData[i].title+'</p>'+
                                '<iframe height="140" width="181" src=\"'+myData[i].url+'\" frameborder=0 allowfullscreen></iframe>'+
                                '<ul class="radiolabel_content" >'+
                                    '<li style="display: inline-block;height: 14px;line-height: 14px;margin: 8px 4px 20px 0;background: #fff;border: none;"><span style="display: inline-block;padding: 3px 5px;text-align: center;border-radius: 3px;font-size: 9px;border: 1px solid #43aaf1;color: #43aaf1;margin: 8px 4px 12px 0;">'+myData[i].channelname+'</span></li>'+
                                    '<li style="display: inline-block;height: 14px;line-height: 14px;margin: 8px 4px 20px 0;background: #fff;border: none;"><span style="display: inline-block;padding: 3px 5px;text-align: center;border-radius: 3px;font-size: 9px;border: 1px solid #43aaf1;color: #43aaf1;margin: 8px 4px 12px 0;">'+myData[i].curriculumtypename+'</span></li>'+
                                    '<li style="display: inline-block;height: 14px;line-height: 14px;margin: 8px 4px 20px 0;background: #fff;border: none;"><span style="display: inline-block;padding: 3px 5px;text-align: center;border-radius: 3px;font-size: 9px;border: 1px solid #43aaf1;color: #43aaf1;margin: 8px 4px 12px 0;">'+myData[i].standardname+'</span></li>'+
                                '</ul>';
                        }
                        str +='</a>'+
                                '<div class="focus_content">'+
                                    '<span><i class="share_num"></i>'+myData[i].forwardcount+'</span>'+
                                    '<span><i class="talk_num"></i>'+myData[i].commentcount+'</span>'+
                                    '<span><i class="well_num'+welldone+'\"></i><em>'+myData[i].praisecount+'</em></span>'+
                                '</div>'+
                               '</div>';
                    }
                    $('#show_item').html(str);
                }
            },
            error: function (data){
                console.log("服务器异常!");
            }
        });
        setTimeout(function(){setHeightKeyWord('published_text', search_val, '#f6ab42', false)},1000);

	}); 
}); 